package com.sto.stoapp.widget;

import android.content.Context;
import android.text.Editable;
import android.text.method.KeyListener;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RadioButton;

import sto.android.app.StoPdaKeyEvent;

public class StoHhmRadioButton extends RadioButton {

	private KeyUpListener keyUpBack;
	
	public StoHhmRadioButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
		init();
	}

	public StoHhmRadioButton(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		init();
	}

	public StoHhmRadioButton(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		init();
	}

	private void init() {
		this.setKeyListener(new KeyListener() {
			
			@Override
			public boolean onKeyUp(View view, Editable text, int keyCode, KeyEvent event) {
				// TODO Auto-generated method stub
				if(keyCode == StoPdaKeyEvent.KEYCODE_DEL){
					if(keyUpBack != null){
						keyUpBack.onKeyUpBack();
					}
				}
				return false;
			}
			
			@Override
			public boolean onKeyOther(View view, Editable text, KeyEvent event) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public boolean onKeyDown(View view, Editable text, int keyCode,
					KeyEvent event) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public int getInputType() {
				// TODO Auto-generated method stub
				return 0;
			}
			
			@Override
			public void clearMetaKeyState(View view, Editable content, int states) {
				// TODO Auto-generated method stub
				
			}
		});
	}
	
	public void setKeyUpBack(KeyUpListener keyUpBack) {
        this.keyUpBack = keyUpBack;
    }
	
	public interface KeyUpListener {
		void onKeyUpBack();
        
    }
	
}
